;
window.onload=function(){

    rightNav();
    slide();
    leftNav();
    backTop();
    $("#login .close").click(function () {
        $('#login').remove();
    });
};




function moveScrollTop(id) {
    moveTop($(id)[0]);
}

function leftNav() {

    $('#xuanting .cate_a').each(function () {
        $(this).click(function () {
            $('#xuanting .cate_a').css({"background":"#918888"});
            $(this).css({"background":"#D70B1C"});
            moveScrollTop($(this).attr('href'));
        }).mouseover(function () {
            $('#xuanting .cate_a').css({"background":"#918888"});
            $(this).css({"background":"#D70B1C"});
        }).mouseout(function () {
            $(this).css({"background":"#918888"});
        });
    });

    window.onscroll=function() {
        var scrollTop=parseInt(document.documentElement.scrollTop||document.body.scrollTop);

        var showPos = parseInt(document.getElementById('index-content').offsetTop);
        // 顶部悬浮
        var oHide_top=$('#hide_top');
        if(scrollTop>(showPos-100)){
            oHide_top.show();
        }else{
            oHide_top.hide();
        }
        // 顶部悬浮结束
        var oXuanting=document.getElementById('xuanting');
        // 左侧中间悬停
        var cateShowPos = $('.category-floor').first().offset().top;
        if(scrollTop>cateShowPos-140) {
            oXuanting.style.display ='block';
        }else{
            oXuanting.style.display ='none';
        }

        var aXuanlink=oXuanting.getElementsByTagName('a');
        var aLen = aXuanlink.length;
        for (var i=0; i<aLen; i++){
            var id = $(aXuanlink[i]).attr('href');
            if(!$(aXuanlink[i]).hasClass('last_a')){
                changeColor(id,i)
            }
        }
        function changeColor(id,num) {
            var nowTop=$(id).offset().top-scrollTop;
            var seeHeight=parseInt(document.documentElement.clientHeight/2);
            if(nowTop>=0&&nowTop<=seeHeight) {
                if(!$(aXuanlink[num+1]).hasClass('last_a')){
                    aXuanlink[num+1].style.background='#918888';
                }
                aXuanlink[num].style.background='#D70B1C';
                if(aXuanlink[num-1]!=undefined){
                    aXuanlink[num-1].style.background='#918888';
                }

            }
        }
    };
}

/**
 * 轮播图
 */
function slide() {
    var oNull=document.getElementById('null_content');
    if (oNull == undefined){
        return;
    }
    var oCondiv=getClass(oNull,'content_midd_top')[0];
    var oPrev=getClass(oNull,'prev')[0];
    var oNext=getClass(oNull,'next')[0];
    var aShow_btn=getClass(oNull,'show_img');
    var aPic=getClass(oNull,'pic_info');
    var now=0;
    var nowZindex=2;
    // alert(aPic.length);
    oCondiv.onmouseover=function()
    {
        oPrev.style.display = 'block';
        oNext.style.display = 'block';
        clearInterval(timer);
    };
    oCondiv.onmouseout=function()
    {
        oPrev.style.display = 'none';
        oNext.style.display = 'none';
        timer=setInterval(oNext.onclick,2000);
    };
    oPrev.onmouseover=oNext.onmouseover=function()
    {
        startmove(oPrev,{opacity:80});
    };
    oNext.onmouseover=function()
    {
        startmove(oNext,{opacity:80});
    }
    oPrev.onmouseout=function()
    {
        startmove(oPrev,{opacity:50});

    };
    oNext.onmouseout=function()
    {
        startmove(oNext,{opacity:50});
    };

    for(var i=0;i<aShow_btn.length;i++)
    {
        aShow_btn[i].index=i;
        aShow_btn[i].onmouseover=function()
        {
            if(this.index==now)return;
            now=this.index;

            tab();
        }
    }
    function tab()
    {
        for(var i=0;i<aShow_btn.length;i++)
        {
            aShow_btn[i].style.background='#FFFFFF';
        }
        aPic[now].style.zIndex =nowZindex++;
        aPic[now].style.width=0;
        startmove(aPic[now],{width:790});
        aShow_btn[now].style.background='#DB192A';
    }
    oPrev.onclick=function()
    {
        now--;
        if(now==-1)
        {
            now=aPic.length-1;
        }
        tab();
    };
    oNext.onclick=function(){
        now++;
        if(now==aPic.length){
            now=0;
        }
        tab();
    };
    var timer=setInterval(oNext.onclick,2000);

    var aHide_div=getClass(oNull,'hide_right_info');
    var aHide_li=getClass(oNull,'hide_left');
    // alert(aHide_div.length);
    for(var i=0;i<aHide_li.length;i++)
    {
        aHide_li[i].index=i;
        aHide_li[i].onmouseover=function()
        {
            aHide_li[this.index].style.background='#999395';
            aHide_div[this.index].style.display='block';
        };
        aHide_li[i].onmouseout=function()
        {
            aHide_li[this.index].style.background='#6E6568';
            aHide_div[this.index].style.display='none';
        };
    }
    function getClass(oParent,sClass) {
        var aResult=[];
        var aEle=oParent.getElementsByTagName('*');
        for(var i=0;i<aEle.length;i++){
            if(aEle[i].className==sClass){
                aResult.push(aEle[i]);
            }
        }
        return aResult;
    }
}